package acwing._2LanQiao._3Math_DP;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @Project : ProgrammingExercises
 * @Package : ACWing._2LanQiao._3Math_DP
 * @File : Q1015.java
 * @Author : WangRuoyu
 * @Date : 2023/3/15 8:43
 */
public class Q1015 {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        String[] words = line.split(" ");

        int t = Integer.parseInt(words[0]);

        for (int i = 0; i < t; ++i) {
            line = br.readLine();
            words = line.split(" ");
            int m = Integer.parseInt(words[0]);
            int n = Integer.parseInt(words[1]);

            int[][] w = new int[m + 1][n + 1];
            int[][] f = new int[m + 1][n + 1];

            for (int j = 1; j <= m; ++j) {
                line = br.readLine();
                words = line.split(" ");
                for (int k = 1; k <= n; ++k) {
                    w[j][k] = Integer.parseInt(words[k - 1]);
                }
            }

            for (int j = 1; j <= m; ++j) {
                for (int k = 1; k <= n; ++k) {
                    f[j][k] = Math.max(f[j - 1][k], f[j][k - 1]) + w[j][k];
                }
            }

            System.out.println(f[m][n]);
        }
    }
}


